
Public Class PrivilegeSystemMenu

    Protected _privilege As New Privilege()
    Protected _system_menu As New SystemMenu()
    Protected _create_user As String
    Protected _create_date As DateTime
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Sub New()

    End Sub

    Public Sub New(ByVal inPrivilegeId As Integer)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getPrivilegeSystemMenu(inPrivilegeId)
    End Sub

    Public Property privilege() As Privilege
        Get
            Return _privilege
        End Get
        Set(ByVal value As Privilege)
            _privilege = value
        End Set
    End Property

    Public Property system_menu() As SystemMenu
        Get
            Return _system_menu
        End Get
        Set(ByVal value As SystemMenu)
            _system_menu = value
        End Set
    End Property

    Public Property create_user() As String
        Get
            Return _create_user
        End Get
        Set(ByVal value As String)
            _create_user = value
        End Set
    End Property

    Public Property create_date() As DateTime
        Get
            Return _create_date
        End Get
        Set(ByVal value As DateTime)
            _create_date = value
        End Set
    End Property

    Protected Function getPrivilegeMainSystemMenu(ByVal inPrivilegeId As Integer) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PrivilegeMainSystemMenu"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeId", inPrivilegeId)
        objCmd.Parameters.Add(objParam)
        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tablePrivilegeMainSystemMenu")

        For Each objDr As System.Data.DataRow In objDs.Tables("tablePrivilegeMainSystemMenu").Rows
            Dim obj As PrivilegeSystemMenu = New PoliceHealthClass.PrivilegeSystemMenu()
            obj.privilege.privilege_id = objDr.Item("privilege_id").ToString()
            obj.privilege.privilege_name_tha = objDr.Item("privilege_name_tha").ToString()
            obj.privilege.privilege_name_eng = objDr.Item("privilege_name_eng").ToString()
            obj.privilege.description = objDr.Item("description").ToString()
            obj.system_menu.system_menu_name_tha = objDr.Item("system_menu_name_tha").ToString()
            obj.system_menu.system_menu_name_eng = objDr.Item("system_menu_name_eng").ToString()
            obj.system_menu.system_parent_menu_id = objDr.Item("system_parent_menu_id").ToString()
            obj.system_menu.system_menu_form = objDr.Item("system_menu_form").ToString()
            obj.system_menu.system_menu_tab = objDr.Item("system_menu_tab").ToString()
            obj.system_menu.system_menu_id = objDr.Item("system_menu_id").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Protected Function getPrivilegeSubSystemMenu(ByVal inParentMenuId As Integer, ByVal inPrivilegeId As Integer) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PrivilegeSubSystemMenu"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inParentMenuId", inParentMenuId)
        Dim objParamPrevilegeId As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeId", inPrivilegeId)
        objCmd.Parameters.Add(objParam)
        objCmd.Parameters.Add(objParamPrevilegeId)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tablePrivilegeSubSystemMenu")

        For Each objDr As System.Data.DataRow In objDs.Tables("tablePrivilegeSubSystemMenu").Rows
            Dim obj As PrivilegeSystemMenu = New PoliceHealthClass.PrivilegeSystemMenu()
            obj.privilege.privilege_id = objDr.Item("privilege_id").ToString()
            obj.privilege.privilege_name_tha = objDr.Item("privilege_name_tha").ToString()
            obj.privilege.privilege_name_eng = objDr.Item("privilege_name_eng").ToString()
            obj.privilege.description = objDr.Item("description").ToString()
            obj.system_menu.system_menu_name_tha = objDr.Item("system_menu_name_tha").ToString()
            obj.system_menu.system_menu_name_eng = objDr.Item("system_menu_name_eng").ToString()
            obj.system_menu.system_parent_menu_id = objDr.Item("system_parent_menu_id").ToString()
            obj.system_menu.system_menu_form = objDr.Item("system_menu_form").ToString()
            obj.system_menu.system_menu_tab = objDr.Item("system_menu_tab").ToString()
            obj.system_menu.system_menu_id = objDr.Item("system_menu_id").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Protected Function getPrivilegeSystemMenu(ByVal inPrivilegeId As Integer) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PrivilegeSystemMenu"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeId", inPrivilegeId)
        objCmd.Parameters.Add(objParam)
        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tablePrivilegeSystemMenu")

        For Each objDr As System.Data.DataRow In objDs.Tables("tablePrivilegeSystemMenu").Rows
            Dim obj As PrivilegeSystemMenu = New PoliceHealthClass.PrivilegeSystemMenu()
            obj.privilege.privilege_id = objDr.Item("privilege_id").ToString()
            obj.privilege.privilege_name_tha = objDr.Item("privilege_name_tha").ToString()
            obj.privilege.privilege_name_eng = objDr.Item("privilege_name_eng").ToString()
            obj.privilege.description = objDr.Item("description").ToString()
            obj.system_menu.system_menu_name_tha = objDr.Item("system_menu_name_tha").ToString()
            obj.system_menu.system_menu_name_eng = objDr.Item("system_menu_name_eng").ToString()
            obj.system_menu.system_parent_menu_id = objDr.Item("system_parent_menu_id").ToString()
            obj.system_menu.system_menu_form = objDr.Item("system_menu_form").ToString()
            obj.system_menu.system_menu_tab = objDr.Item("system_menu_tab").ToString()
            obj.system_menu.system_menu_id = objDr.Item("system_menu_id").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Sub LoadPrivilegeSubSystemMenu(ByVal inParentMenuId As Integer, Optional ByVal inPrivilegeId As Integer = -1)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getPrivilegeSubSystemMenu(inParentMenuId, inPrivilegeId)
    End Sub

    Public Sub LoadPrivilegeMainSystemMenu(ByVal inPrivilegeId As Integer)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getPrivilegeMainSystemMenu(inPrivilegeId)
    End Sub

    Public Sub LoadPrivilegeSystemMenu(ByVal inPrivilegeId As Integer)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getPrivilegeSystemMenu(inPrivilegeId)
    End Sub

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _privilege.privilege_id = _Data(_DataCurrent).privilege.privilege_id
            _privilege.privilege_name_tha = _Data(_DataCurrent).privilege.privilege_name_tha
            _privilege.privilege_name_eng = _Data(_DataCurrent).privilege.privilege_name_eng
            _privilege.description = _Data(_DataCurrent).privilege.description
            _system_menu.system_menu_name_tha = _Data(_DataCurrent).system_menu.system_menu_name_tha
            _system_menu.system_menu_name_eng = _Data(_DataCurrent).system_menu.system_menu_name_eng
            _system_menu.system_parent_menu_id = _Data(_DataCurrent).system_menu.system_parent_menu_id
            _system_menu.system_menu_form = _Data(_DataCurrent).system_menu.system_menu_form
            _system_menu.system_menu_tab = _Data(_DataCurrent).system_menu.system_menu_tab
            _system_menu.system_menu_id = _Data(_DataCurrent).system_menu.system_menu_id
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Function Clone() As PrivilegeSystemMenu
        Return Me
    End Function

    Public Function deletePrivilegeSystemMenu(ByVal inPrivilegeID As Integer) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_PrivilegeSystemMenu"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeID", _
                Utilities.SendToDatabase(inPrivilegeID))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function insertPrivilegeSystemMenu(ByVal inPrivilegeSystemMenu As PrivilegeSystemMenu) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_PrivilegeSystemMenu"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeID", _
                Utilities.SendToDatabase(inPrivilegeSystemMenu.privilege.privilege_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inSystemMenuID", _
                Utilities.SendToDatabase(inPrivilegeSystemMenu.system_menu.system_menu_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCreateUser", _
                Utilities.SendToDatabase(inPrivilegeSystemMenu.create_user))
            objCmd.Parameters.Add(objParam)


            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class
